﻿Imports System.Xml.Linq
Imports System.Text

Namespace Entities
    Public Class Command
        Public Property Name As String
        Public Property Example As String
        Public Property ListenForList As ICollection(Of String) = New List(Of String)
        Public Property Feedback As String
        Public Property NavigateTarget As String

        Public Function GetXml() As String
            If Not Validate() Then Return Nothing
            Dim strBuild = New StringBuilder
            strBuild.AppendFormat("<Command Name=""{0}"">", Name)
            strBuild.AppendLine()
            strBuild.AppendFormat("<Example>{0}</Example>", Example)
            strBuild.AppendLine()
            For Each l In ListenForList
                strBuild.AppendFormat("<ListenFor>{0}</ListenFor>", l)
                strBuild.AppendLine()
            Next
            strBuild.AppendFormat("<Feedback>{0}</Feedback>", Feedback)
            strBuild.AppendLine()
            If String.IsNullOrWhiteSpace(NavigateTarget) Then
                strBuild.AppendFormat("<Navigate />")
            Else
                strBuild.AppendFormat("<Navigate Target={0}/>", NavigateTarget)
            End If
            strBuild.AppendLine()
            strBuild.AppendFormat("</Command>")
            Return strBuild.ToString
        End Function

        Public Function Validate() As Boolean
            If String.IsNullOrWhiteSpace(Name) Then Return False
            If Not ListenForList.Any Then Return False
            Return True
        End Function
    End Class
End Namespace